package top.lshaci.learning.springboot.web.fastjson.reader;

import com.alibaba.fastjson2.JSONReader;
import com.alibaba.fastjson2.reader.ObjectReader;

import java.lang.reflect.Type;
import java.time.YearMonth;

/**
 * ObjectReaderYearMonth
 *
 * @author liangxu
 */
public class ObjectReaderYearMonth implements ObjectReader<YearMonth> {

    public static final ObjectReaderYearMonth INSTANCE = new ObjectReaderYearMonth();

    @Override
    public YearMonth readObject(JSONReader jsonReader, Type fieldType, Object fieldName, long features) {
        if (jsonReader.nextIfNull()) {
            return null;
        }
        String str = jsonReader.readString();
        return YearMonth.parse(str);
    }
}
